package com.cy.ppj.web.admin.customer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.cy.ppj.model.PageBean;
import com.cy.ppj.model.Result;
import com.cy.ppj.model.ao.customer.CustomerAdminEditAO;
import com.cy.ppj.model.query.customer.CustomerListAdminQuery;
import com.cy.ppj.model.vo.customer.CustomerDetailAdminVO;
import com.cy.ppj.model.vo.customer.CustomerListAdminVO;
import com.cy.ppj.model.vo.customer.MallCustomerDetailAdminVO;
import com.cy.ppj.service.customer.CustomerService;
import com.cy.ppj.web.BaseController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 后台-客户管理
 *
 * @author tanyilin
 *
 * @create 2019年2月20日 上午10:02:21
 */
@RestController
@RequestMapping("/admin/customer")
@Api(tags = "后台-客户管理")
public class AdminCustomerController extends BaseController {

	@Autowired
	private CustomerService customerService;
	
	@ApiOperation("客户列表")
	@GetMapping("/list")
	public PageBean<CustomerListAdminVO> list(CustomerListAdminQuery query) {
		PageBean<CustomerListAdminVO> pageBean = customerService.selectCustomerListAdmin(query);
		return pageBean;
	}
	
	@ApiOperation("客户详情")
	@GetMapping("/detail")
	public Result<CustomerDetailAdminVO> detail(@RequestParam(value = "customerId") Long customerId) {
		
		CustomerDetailAdminVO resultVo = customerService.selectCustomerDetailAdmin(customerId);
		
		return ok("", resultVo);
	}
	
	@ApiOperation("编辑保存客户信息")
	@PostMapping("/do/edit")
	public Result doEdit(@RequestBody @Validated CustomerAdminEditAO editAO, BindingResult bindingResult) {
		
		this.checkError(bindingResult);
		
		customerService.doEdit(editAO);
		
		return ok();
	}
	
	@ApiOperation("马先生商城客户详情")
	@GetMapping("/get/mall/customer/detail")
	public Result<MallCustomerDetailAdminVO> getMallCustomerDetailAdminVO(@RequestParam(value = "customerId") Long customerId) {
		MallCustomerDetailAdminVO resultVo = customerService.selectMallCustomerDetailAdminVO(customerId);
		return ok("", resultVo);
	}
	
	
	
}
